/**
 * Created by S on 2016/5/9.
 */
var DBTool=require('commom').DBTool;

exports.insertcontent=function(condition,callback){
    var sql="insert into commoditypicture(name,commodityid) values('" + condition.name +"',"+condition.commodityid +")";
    var params=[];
    DBTool.Execute(sql,params,function(err,data){
        if(err)
        {
            callback(err,null);
        }
        else
        {
            callback(null,data);
        }
    });
}

exports.findcontent = function (condition,callback) {
    var star=false;
    var c="where";
    var sql="select * from commoditypicture ";
    if(condition.id!=undefined){
        if(star)
            c=c+" and ";
        c=c+" id = "+condition.id;
        star=true;
    }
    if(condition.name!=undefined){
        if(star)
            c=c+" and ";
        c=c+" name = '"+condition.name+"'";
        star=true;
    }
    if(condition.commodityid!=undefined){
        if(star)
            c=c+" and ";
        c=c+" commodityid = "+condition.commodityid;
        star=true;
    }
    if(c!="where"){
        sql=sql + c;
    }
    var params=[];
    DBTool.Execute(sql,params, function ( err, data ) {
        if(err)
        {
            callback(err,null);
        }
        else
        {
            callback(null,data);
        }
    });
};

exports.deletecontent=function(condition,callback){
    var sql="delete commoditypicture";
    if(condition.id!=undefined){
        sql=sql+" where id = "+condition.id;
    }
    else if(condition.commodityid!=undefined){
        sql=sql+" where commodityid = "+condition.commodityid;
    }
    var params=[];
    DBTool.Execute(sql,params,function(err,data){
        if(err)
        {
            callback(err,null);
        }
        else
        {
            callback(null,data);
        }
    });
}